import 'dart:async';

import 'package:flutter/material.dart';

class TencentFlutterFlog {
  static StreamController<bool> _flogReporter;

// 日志流
  static Stream<bool> get flogStream {
    if (_flogReporter == null) {
      _flogReporter = StreamController<bool>.broadcast();
    }
    return _flogReporter.stream;
  }
}

class StreamHomePage extends StatefulWidget {
  StreamHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _StreamHomePageState createState() => _StreamHomePageState();
}

class _StreamHomePageState extends State<StreamHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    if (TencentFlutterFlog._flogReporter != null) {
      TencentFlutterFlog._flogReporter.add(true);
    }
  }

  @override
  void initState() {
    super.initState();
    TencentFlutterFlog.flogStream.listen((bool messageObject) {
      print('$messageObject, ');
    });

    TencentFlutterFlog.flogStream.listen((bool messageObject) {
      print('22222  $messageObject, ');
    });

    TencentFlutterFlog.flogStream.listen((bool messageObject) {
      print('33333  $messageObject, ');
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headline4,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}
